package com.pethome.pet.controller;

import com.pethome.common.annotation.Log;
import com.pethome.common.core.controller.BaseController;
import com.pethome.common.core.domain.AjaxResult;
import com.pethome.common.core.page.TableDataInfo;
import com.pethome.common.enums.BusinessType;
import com.pethome.common.utils.poi.ExcelUtil;
import com.pethome.pet.domain.Disease;
import com.pethome.pet.service.IDiseaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 常见疾病Controller
 * 
 * @author 胡继承
 * @date 2024-09-02
 */
@Slf4j
@RestController
@RequestMapping("/pet/disease")
public class DiseaseController extends BaseController
{
    @Autowired
    private IDiseaseService diseaseService;


    @GetMapping("/plussSearchCount")
    public boolean plussSearchCount(Disease disease){
        log.info(disease.getDiseaseSearchCount().toString());
        return diseaseService.plussSearchCount(disease);
    }


    /**
     * 获取全部疾病列表
     */
    @GetMapping("/getAll")
    public TableDataInfo getAll()
    {
        Disease disease =new Disease();
        List<Disease> list = diseaseService.selectDiseaseList(disease);
        return getDataTable(list);
    }


    /**
     * 获取热度前5条疾病列表
     */
    @GetMapping("/getTop5")
    public TableDataInfo getTop5()
    {
        List<Disease> list = diseaseService.getTop5();
        return getDataTable(list);
    }





    /**
     * 查询常见疾病列表
     */
    @PreAuthorize("@ss.hasPermi('pet:disease:list')")
    @GetMapping("/list")
    public TableDataInfo list(Disease disease)
    {
        startPage();
        List<Disease> list = diseaseService.selectDiseaseList(disease);
        return getDataTable(list);
    }

    /**
     * 导出常见疾病列表
     */
    @PreAuthorize("@ss.hasPermi('pet:disease:export')")
    @Log(title = "常见疾病", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Disease disease)
    {
        List<Disease> list = diseaseService.selectDiseaseList(disease);
        ExcelUtil<Disease> util = new ExcelUtil<Disease>(Disease.class);
        util.exportExcel(response, list, "常见疾病数据");
    }

    /**
     * 获取常见疾病详细信息
     */
    @PreAuthorize("@ss.hasPermi('pet:disease:query')")
    @GetMapping(value = "/{diseaseId}")
    public AjaxResult getInfo(@PathVariable("diseaseId") Long diseaseId)
    {
        return success(diseaseService.selectDiseaseByDiseaseId(diseaseId));
    }

    /**
     * 新增常见疾病
     */
    @PreAuthorize("@ss.hasPermi('pet:disease:add')")
    @Log(title = "常见疾病", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Disease disease)
    {
        return toAjax(diseaseService.insertDisease(disease));
    }

    /**
     * 修改常见疾病
     */
    @PreAuthorize("@ss.hasPermi('pet:disease:edit')")
    @Log(title = "常见疾病", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Disease disease)
    {
        return toAjax(diseaseService.updateDisease(disease));
    }

    /**
     * 删除常见疾病
     */
    @PreAuthorize("@ss.hasPermi('pet:disease:remove')")
    @Log(title = "常见疾病", businessType = BusinessType.DELETE)
	@DeleteMapping("/{diseaseIds}")
    public AjaxResult remove(@PathVariable Long[] diseaseIds)
    {
        return toAjax(diseaseService.deleteDiseaseByDiseaseIds(diseaseIds));
    }
}
